import { fileAnalysis } from "@/views/wy-asset-management/fixed-warehousing/api/fixed-warehousing.js";
import firstStep from './step/fist-step.vue';
import twoStep from './step/two-step.vue'
import threeStep from './step/three-step.vue'
import { getDict } from "~/utils";

export default {
    components: {
        firstStep: firstStep,
        twoStep: twoStep,
        threeStep: threeStep
    },
    data () {

        return {
            loading: true,
            //初始步骤
            active: 1,

            firstStepHide: false,
            twoStepHide: false,
            threeStepHide: false,

            //文件路径
            filePath: '',

            //文件解析返回值
            successList: [],
            errorList: [],
            mes: [],
            flag: false,



        }
    },
    /**
     * 载入事件
     */
    mounted () {
        this.stepShow();
    },
    created () {
    },
    methods: {
        stepShow () {
            this.loading = false;
            if (this.active == 1) {
                this.firstStepHide = true;
                this.twoStepHide = false;
                this.threeStepHide = false;
            } else if (this.active == 2) {
                this.firstStepHide = false;
                this.twoStepHide = true;
                this.threeStepHide = false;
            } else if (this.active == 3) {
                this.firstStepHide = false;
                this.twoStepHide = false;
                this.threeStepHide = true;
            }
        },


        /**
         * 下一步
         */
        next () {

            //第一步跳到第二步
            if (this.active == 1) {
                this.loading = true;
                if (this.$refs.firstStep.$data.fileList == '') {
                    this.$message({
                        type: 'info',
                        message: '请先提交上传文件'
                    });
                    this.loading = false;
                    return;
                }

                //获取子页面的文件路径
                this.filePath = this.$refs.firstStep.$data.fileList[0].path;

                //解析文件 fileAnalysis
                fileAnalysis(this.filePath).then((resp) => {
                    this.errorList = resp.data.data.errorList;
                    this.successList = resp.data.data.successList;
                    this.mes = resp.data.data.mes;
                    this.flag = resp.data.data.flag;

                    this.loading = false;
                    if (this.flag == false) {
                        this.$message({
                            type: 'info',
                            message: '文件解析没有数据，请检查上传的文件是否正确'
                        });
                    } else {
                        this.active = this.active + 1;
                        this.stepShow();
                    }

                }).catch(error => {
                    this.$message({
                        type: 'error',
                        message: '文件解析失败'
                    });
                }).finally(() => this.loading = false);
            }

            //第二步到结束
            if (this.active == 2) {
                this.active = this.active + 1;
                this.stepShow();
            }


        },

        /**
         * 上一步
         */
        goBack () {
            this.active = this.active - 1;
            this.stepShow();
        },

        /**
         * 返回列表
         */
        goList () {
            this.$router.push('/asset-management/fixed-warehousing-list');
        }z
    }

}
